<template>
  <div class="home">
    <el-container>
      <el-header>
         <h1>后台管理</h1>   
        <el-button class="tui" @click="logout">退出</el-button>
      </el-header>
      
      <el-container>
        <el-aside width="201px">
         <el-menu
            router
            unique-opened
            :collapse="isCollapse"
            :collapse-transition="false"
            background-color="#333744"
            text-color="#fff"
            active-text-color="#ffd04b">
            <!-- 一级菜单 -->
            <el-submenu 
              :index="item.id+''" 
              v-for="item in menulist" 
              :key="item.id">
              <!-- 一级菜单模板 -->
              <template slot="title">
                <!-- 图标 -->
                <i :class="iconsObj[item.id]"></i>
                <!-- 文本 -->
                <span>{{item.authName}}</span>
              </template>
              <!-- 二级子菜单 -->
              <el-menu-item 
            
              :index="'/' + subItem.path"
               v-for="subItem in item.children" 
               :key="subItem.id"
               @click="saveNav('/'+subItem.path)">
                <!-- 二级菜单模板 -->
                <template slot="title">
                  <!-- 图标 -->
                  <i class="el-icon-menu"></i>
                  <!-- 文本 -->
                  <span>{{subItem.authName}}</span>
                </template>
              </el-menu-item>
            </el-submenu>
            
          </el-menu>
        </el-aside>

        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
// @ is an alias to /src

export default {
  name: 'Home',
  data(){
    return {
      aPath:"",
      menulist:[],
      iconsObj:{
        125: 'el-icon-user',
        103: 'el-icon-s-custom',
        101: 'el-icon-goods',
        102: 'el-icon-s-finance',
        145: 'el-icon-s-marketing',
      },
      isCollapse:false,
    }
  },
  created(){
    this.getMenulist()
  },
  methods:{
    //登出
    logout(){
      window.sessionStorage.removeItem("token");
      this.$router.push("/login")
    },
    async getMenulist(){
      const {data:res} = await this.$http.get("menus");
      if(res.meta.status !== 200) return this.$message.error(res.meta.msg);
      this.menulist = res.data;
    },
    saveNav(aPath){
      window.sessionStorage.setItem("path",aPath);
      this.path = aPath
    }
  }
}
</script>
<style lang="less" scoped>
  .home{
    height: 100%;
  }
  .el-container{
    height: 100%;
  }
  .el-header, .el-footer {
    background-color: #B3C0D1;
    color: #333;
    // text-align: center;
    line-height: 60px;
  }
  
  .el-aside {
    background-color: #D3DCE6;
    color: #333;
    // text-align: center;
    
    line-height: 200px;
  }
  
  .el-main {
    background-color: #E9EEF3;
    color: #333;
    text-align: center;
    // line-height: 160px;
  }
  
  body > .el-container {
    margin-bottom: 40px;
  }
  
  .el-container:nth-child(5) .el-aside,
  .el-container:nth-child(6) .el-aside {
    line-height: 260px;
  }
  
  .el-container:nth-child(7) .el-aside {
    line-height: 320px;
  }
  h1{
    display: inline;
  }
  .tui{
    float: right;
    display: flex;
    margin-top: 10px;
  }
</style>